<?php
    /**
     * 实现array_column部分功能
     * @param array $array 输入数组
     * @param str $key  输出数组键
     * @param str $value 输出二级数组键
     */
    function larray_column($array,$key,$value=''){
        //参数验证
        if(!is_array($array)){
            throw new Exception('invalid input array');
        }
        foreach($array as $k=>$v){
            if(!in_array($key,array_keys($v))){
                throw new Exception('output array key not exists in input array');
            }
            if($value){
                if(array_diff(explode(',',$value),array_keys($v))){
                    throw new Exception("output array key not completly in original array keys");
                }
            }
        }
        //数组置换
        $outputArr = array();
        $terminalKeyArr = array();
        //是否指定输出数组键
        if($value){
            $terminalKeyArr = explode(',',$value);
            for($i=0,$inputArrayLength=count($array);$i<$inputArrayLength;$i++){
                $tmpArr = array();
                for($j=0,$outputKeyLength=count($terminalKeyArr);$j<$outputKeyLength;$j++){
                    $tmpArr[$terminalKeyArr[$j]] = $array[$i][$terminalKeyArr[$j]];
                }
                $outputArr[$array[$i][$key]] = $tmpArr;
            }
        }else{
            array_walk($array,function($v,$k)use(&$terminalKeyArr,$key){
                array_push($terminalKeyArr,$v[$key]);
            });
            $outputArr = array_combine($terminalKeyArr,$array);
        }
        return $outputArr;
    }